package gui;

import org.eclipse.jface.action.MenuManager;


import org.eclipse.jface.action.StatusLineManager;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.wb.swt.SWTResourceManager;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.widgets.Label;

public class PruebaJFaces extends ApplicationWindow {
	private Action action_1;
	private Label RutaL;
	Composite container;

	/**
	 * Create the application window.
	 */
	public PruebaJFaces() {
		super(null);
		createActions();
		addToolBar(SWT.FLAT | SWT.WRAP);
		addMenuBar();
		addStatusLine();
	}

	/**
	 * Create contents of the application window.
	 * @param parent
	 */
	@Override
	protected Control createContents(Composite parent) {
		container = new Composite(parent, SWT.NONE);
		
	    
	    RutaL = new Label(container, SWT.WRAP);
	    RutaL.setBounds(451, 201, 193, 25);

		return container;
	}

	/**
	 * Create the actions.
	 */
	private void createActions() {
		// Create the actions
		{
			action_1 = new Action("Abrir") {

				@Override
				public void run() {
					// TODO Auto-generated method stub
					super.run();
					FileDialog open = new FileDialog(getShell(), SWT.OPEN);
					open.setText("Abrir");
					open.setFilterExtensions(new String[]{"*.txt","*.*"});
					open.setFilterNames(new String[]{"Archivos de texto (.txt)","Todos los archivos"});
					String ruta = open.open();
					RutaL.setText(ruta);
					RutaL.pack();
					RutaL.setLocation((container.getSize().x - RutaL.getSize().x)/2,container.getSize().y/2);
					
				}
			};
		}
	}

	/**
	 * Create the menu manager.
	 * @return the menu manager
	 */
	@Override
	protected MenuManager createMenuManager() {
		MenuManager menuManager = new MenuManager("menu");
		menuManager.setActionDefinitionId("");
		{
			MenuManager menuManager_1 = new MenuManager("Archivo");
			menuManager.add(menuManager_1);
			menuManager_1.add(action_1);
		}
		return menuManager;
	}

	/**
	 * Create the toolbar manager.
	 * @return the toolbar manager
	 */
	@Override
	protected ToolBarManager createToolBarManager(int style) {
		ToolBarManager toolBarManager = new ToolBarManager(style);
		return toolBarManager;
	}

	/**
	 * Create the status line manager.
	 * @return the status line manager
	 */
	@Override
	protected StatusLineManager createStatusLineManager() {
		StatusLineManager statusLineManager = new StatusLineManager();
		return statusLineManager;
	}

	/**
	 * Launch the application.
	 * @param args
	 */
	public static void main(String args[]) {
		try {
			PruebaJFaces window = new PruebaJFaces();
			window.setBlockOnOpen(true);
			window.open();
			Display.getCurrent().dispose();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Configure the shell.
	 * @param newShell
	 */
	@Override
	protected void configureShell(Shell newShell) {
		newShell.setImage(SWTResourceManager.getImage(PruebaJFaces.class, "/javax/swing/plaf/basic/icons/JavaCup16.png"));
		super.configureShell(newShell);
		newShell.setText("New Application");
	}

	/**
	 * Return the initial size of the window.
	 */
	@Override
	protected Point getInitialSize() {
		return new Point(450, 300);
	}
	public Label getRutaL() {
		return RutaL;
	}
}
